package com.aix.android.framework.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.widget.ScrollView;

public class DragDropScrollView extends ScrollView {
	
	private float prevY;
	
    private static final int MAX_Y_OVERSCROLL_DISTANCE = 200;

    private Context mContext;
    private int mMaxYOverscrollDistance;

	public DragDropScrollView(Context context, AttributeSet attrs) {
		super(context, attrs);
		
//		setOnTouchListener(new OnTouchListener() {
//			
//			@Override
//			public boolean onTouch(View v, MotionEvent event) {
//				ScrollView scrollView = (ScrollView) v;
//				if (scrollView.getScrollY() == 0) {
//					switch (event.getAction()) {
//					case MotionEvent.ACTION_DOWN:
//						prevY = event.getY();
//						break;
//					case MotionEvent.ACTION_MOVE:
//						float currentY = event.getY();
//						if (curr)
//					}
//				}
//				return false;
//			}
//		});
		
		setOverScrollMode(OVER_SCROLL_ALWAYS);
		
        mContext = context;
        initBounceScrollView();
	}
	
    private void initBounceScrollView()
    {
        //get the density of the screen and do some maths with it on the max overscroll distance
        //variable so that you get similar behaviors no matter what the screen size

        final DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
            final float density = metrics.density;

        mMaxYOverscrollDistance = (int) (density * MAX_Y_OVERSCROLL_DISTANCE);
    }

    @Override
    protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX, int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) 
    { 
        //This is where the magic happens, we have replaced the incoming maxOverScrollY with our own custom variable mMaxYOverscrollDistance; 
        return super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX, scrollRangeY, maxOverScrollX, mMaxYOverscrollDistance, isTouchEvent);  
    }
	
}
